package com.lastproject.ejb.util;

import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import com.lastproject.dto.DomainDTO;
import com.lastproject.ejb.entities.Domain;

/**
 * Session Bean implementation class DomainConversion
 */
@Stateless
@LocalBean
public class DomainConversion{

	@PersistenceContext
	EntityManager em;

    public DomainConversion() {
    }
    
    public DomainDTO fromEntity(Domain u){
    	DomainDTO domain = new DomainDTO();
    	domain.setId(u.getId());
    	domain.setName(u.getName());
    	return domain;
    }
    
    public Domain fromDTO(DomainDTO u){
    	Domain domain = em.find(Domain.class, u.getId()); 
    	if(domain==null)
    		domain = new Domain();
    	domain.setName(u.getName());
    	return domain;
    }
}
